﻿namespace Digitalmes.Common.Exceptions;

/// <summary>
/// 业务抛异常静态类。
/// </summary>
public static class Oops
{
    /// <summary>
    /// 抛出业务异常信息
    /// </summary>
    /// <param name="errorMessage">异常消息</param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException" />
    public static void ThrowBah(string? errorMessage)
    {
        throw Bah(errorMessage);
    }

    /// <summary>
    /// 抛出业务异常信息
    /// </summary>
    /// <param name="errorCode">错误码</param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException" />
    public static void ThrowBah(Enum errorCode, string? errorMessage = null)
    {
        throw Bah(errorCode, errorMessage);
    }

    /// <summary>
    /// 抛出业务异常信息
    /// </summary>
    /// <param name="errorCode">错误码</param>
    /// <param name="errorMessage">异常消息</param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException" />
    public static void ThrowBah(int errorCode, string? errorMessage = null)
    {
        throw Bah(errorCode, errorMessage);
    }

    /// <summary>
    /// 反馈业务异常信息
    /// </summary>
    /// <param name="errorMessage">异常消息</param>
    /// <returns></returns>
    public static UserFriendlyException Bah(string? errorMessage)
    {
        return new UserFriendlyException(message: errorMessage);
    }

    /// <summary>
    /// 反馈业务异常信息
    /// </summary>
    /// <param name="errorCode">错误码</param>
    /// <param name="errorMessage">异常消息</param>
    /// <returns></returns>
    public static UserFriendlyException Bah(Enum errorCode, string? errorMessage = null)
    {
        var desc = errorMessage ?? errorCode.Description();
        return new UserFriendlyException(Convert.ToInt32(errorCode), desc);
    }

    /// <summary>
    /// 反馈业务异常信息
    /// </summary>
    /// <param name="errorCode">错误码</param>
    /// <param name="errorMessage">异常消息</param>
    /// <returns></returns>
    public static UserFriendlyException Bah(int errorCode, string? errorMessage = null)
    {
        return new UserFriendlyException(errorCode, errorMessage);
    }
}
